package com.example.bms.mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.bms.entity.ExamManage;
import org.apache.ibatis.annotations.*;
import java.util.List;


/**
 * @apiNote 进行试卷的增删改查
 * @author 钟顺浩
 * @email 2918185121@qq.com
 * @since 1.0.0
 */
@Mapper
public interface ExamManageMapper {
    /**
     * @apiNote 不分页查询所有试卷
     * @author 钟顺浩
     * @email 2918185121@qq.com
     * @return List<ExamManage>
     * @since 1.0.0
     */
    @Select("select * from exam_manage")
    List<ExamManage> findAll();


    /**
     * @apiNote 分页查询所有试卷
     * @author 钟顺浩
     * @param page 页数
     * @email 2918185121@qq.com
     * @return IPage<ExamManage>
     * @since 1.0.0
     */
    @Select("select * from exam_manage")
    IPage<ExamManage> findAllPage(Page page);



    /**
     * @apiNote 根据考试编号查找试卷所有信息
     * @author 钟顺浩
     * @param examCode 考试编号
     * @email 2918185121@qq.com
     * @return ExamManage
     * @since 1.0.0
     */
    @Select("select * from exam_manage where examCode = #{examCode}")
    ExamManage findById(Integer examCode);


    /**
     * @apiNote 根据考试编号进行删除试卷
     * @author 钟顺浩
     * @param examCode 考试编号
     * @email 2918185121@qq.com
     * @return int类型，受影响的条数
     * @since 1.0.0
     */
    @Delete("delete from exam_manage where examCode = #{examCode}")
    int delete(Integer examCode);


    /**
     * @apiNote 修改试卷信息
     * @author 钟顺浩
     * @param exammanage
     * - examCode 考试编号
     * - description 考试描述
     * - source 课程名称
     * - paperId 试卷编号
     * - examDate 考试发布时间
     * - totalTime 考试总时长
     * - grade 年级
     * - term 学期
     * - major 专业
     * - totalScore 考试满分
     * - type 考试类型（期末考试，公选课考试，期中考试）
     * - tips 考试要求，建议
     * @email 2918185121@qq.com
     * @return int类型，受影响的条数
     * @since 1.0.0
     */
    @Update("update exam_manage set description = #{description},source = #{source},paperId = #{paperId}," +
            "examDate = #{examDate},totalTime = #{totalTime},grade = #{grade},term = #{term}," +
            "major = #{major},institute = #{institute},totalScore = #{totalScore}," +
            "type = #{type},tips = #{tips} where examCode = #{examCode}")
    int update(ExamManage exammanage);


    /**
     * @apiNote 增加试卷
     * @author 钟顺浩
     * @param exammanage
     * - examCode 考试编号
     * - description 考试描述
     * - source 课程名称
     * - paperId 试卷编号
     * - examDate 考试发布时间
     * - totalTime 考试总时长
     * - grade 年级
     * - term 学期
     * - major 专业
     * - totalScore 考试满分
     * - type 考试类型（期末考试，公选课考试，期中考试）
     * - tips 考试要求，建议
     * @email 2918185121@qq.com
     * @return int，插入成功返回1，插入失败返回0
     * @since 1.0.0
     */
    @Options(useGeneratedKeys = true,keyProperty = "examCode")
    @Insert("insert into exam_manage(description,source,paperId,examDate,totalTime,grade,term,major,institute,totalScore,type,tips)" +
            " values(#{description},#{source},#{paperId},#{examDate},#{totalTime},#{grade},#{term},#{major},#{institute},#{totalScore},#{type},#{tips})")
    int add(ExamManage exammanage);


    /**
     * @apiNote 查询最后一条记录的paperId,返回给前端达到自增效果
     * @author 钟顺浩
     * - paperId 试卷编号
     * @email 2918185121@qq.com
     * @return ExamManage
     * @since 1.0.0
     */
    @Select("select paperId from exam_manage order by paperId desc limit 1")
    ExamManage findOnlyPaperId();
}
